<template>
  <div class="toStroke">
    <div class="container">

      <createTop firstMenu="生产单详情" secondMenu="商品入库" title="入库" :showAddBtn="false"></createTop>
      <el-button
        size="small"
        plain
        type="primary"
        class="back"
        @click="$to('productList')">返回</el-button>
      <!-- 第一个表格 -->
      <el-card class="first">
        <div class="first-title">
          <div class="right">
            <div class="right-top">
              <div><span class="big">生产单号: </span>{{row.sc_order}}</div>
              <div><span class="big">销售员: </span>{{row.sell_username}}</div>
              <div><span class="big">交货日期: </span>{{row.date}}</div>
            </div>
            <div class="right-bottom">
              <div><span class="big">订单号: </span>{{row.order}}</div>
            </div>
          </div>
        </div>
      
        <el-table
        :border="true"
        :data="tableData"
        style="width: 100%"
        :fit="true"
        :stripe="true"
        size="mini"
        align="center">


          <el-table-column
            prop="goods_number"
            label="商品编号"
            min-width="100"
            align="center">
          </el-table-column>

          <el-table-column
            prop="goods_name"
            label="商品名称"
            min-width="130"
            align="center">
          </el-table-column>

          <el-table-column
            prop="class_name"
            label="类别"
            min-width="130"
            align="center">
          </el-table-column>

          <el-table-column
            prop="goods_model"
            label="型号"
            min-width="120"
            align="center">
          </el-table-column>

          <el-table-column
            prop="goods_model"
            label="单位"
            min-width="120"
            align="center">
          </el-table-column>

          <el-table-column
            prop="count"
            label="生产数量"
            min-width="120"
            align="center">
          </el-table-column>

          <el-table-column 
          label="入库数量"
          min-width="180"
          align="center">
            <template slot-scope="scope">
              <el-input 
              v-model="scope.row.outCount" 
              @blur="changeOutCount(scope)"
              placeholder="输入入库数量"></el-input>
            </template>
          </el-table-column>

          <el-table-column 
          label="备注"
          min-width="180"
          align="center">
            <template slot-scope="scope">
              <el-input 
              v-model="scope.row.tableRemark" 
              placeholder="填写备注"></el-input>
            </template>
          </el-table-column>

        </el-table>
        </el-card>

      <el-card shadow="always">
        <div slot="header" class="card-title">
          <span>入库信息</span>
        </div>
        <div class="content">
          <div class="se">
            <div class="content-title">制单人</div>
            <el-input :style="{'width':'350px'}" disabled v-model="makename" placeholder="读取账号"></el-input>
          </div>

          <div class="se">  
            <div class="content-title">出库单号 </div>
            <el-input :style="{'width':'350px'}" disabled v-model="rukuid" placeholder="自动填充"></el-input>
          </div>
        </div>

        <div class="content">
          <div class="se">

          <div class="content-title">入库日期 <span class="red-icon">※</span></div>
            <el-date-picker
              v-model="date"
              type="date"
              placeholder="选择日期时间"
              value-format="yyyy-MM-dd">
            </el-date-picker>

          <div class="content-title">入库类型 </div>
            <el-input :style="{'width':'350px'}" disabled v-model="leixing" placeholder="输入适当的备注方便管理"></el-input>

          <div class="content-title">经办人 <span class="red-icon">※</span> </div>
            <el-input :style="{'width':'350px'}" v-model="doname" placeholder="输入经办人姓名"></el-input>
          </div>
          <div class="se">

          <div class="content-title">入库备注</div>
            <el-input :style="{'width':'350px'}" v-model="remark" type="textarea" :rows="5" resize="none" placeholder="输入适当的备注方便管理"></el-input>
          </div>
        </div>
      </el-card>
        <el-button
        class="confirms"
        size="small"
        type="primary"
        @click="confirm">入 库</el-button>

      <el-dialog
      v-if="showCheck"
        title=""
        :visible="true"
        width="30%"
        :show-close="false">
        <span>商品数量 : {{checkMessage}}</span>
        <span slot="footer" class="dialog-footer">
          <el-button plain type="primary" @click="showCheck = false">取 消</el-button>
          <el-button type="primary" @click="secondConfirm">确 定</el-button>
        </span>
      </el-dialog>

    </div>
  </div>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import createTop from '@/components/createTop.vue';
import saveBtn from '@/components/saveBtn.vue';
import ajaxResquest from '@/api/apiRequest';
import childTable from '@/tables/order/productListWaitChild.vue';
@Component({
  components: {
    createTop,
    saveBtn,
    childTable
  }
})
export default class ToStroke extends Vue {
  createRes!: ajaxResquest;
  infoRes!: ajaxResquest;
  checkRes!: ajaxResquest;

  row: any = [];

  tableData: any[] = [];

  makename: string = '';
  outCount: string = '';
  tableRemark: string = '';
  showMask: boolean = false;
  leixing: string = '';
  doname: string = '';
  rukuid: string = '';
  remark: string = '';
  doName: string = '';
  date: any = '';
  showChild: boolean = false;
  $router!: any;
  id: any = '';
  showCheck: boolean = false;
  checkMessage: string = '';
  created() {
    this.id = this.$route.query.id;
  }
  mounted() {
    this.infoRes = new ajaxResquest('/order/productionsInList');
    this.createRes = new ajaxResquest('/order/productionsIn');
    this.checkRes = new ajaxResquest('/order/getGoodsNumber');
    this.getInfo();
  }
  getInfo() {
    this.infoRes.getFunction({ orderId: this.id }).then((res: any) => {
      let temp: any[] = res.data.data.types.goods;
      this.tableData = temp;
      this.tableData[0].outCount=this.tableData[0].count
      this.row = res.data.data.types.orderInfo;
      console.log(this.row);
    });
  }
  add(val: any) {
    console.log(val);
    this.showChild = true;
  }
  del(index: number, val: any) {
    this.tableData.splice(index, 1);
  }
  closeChild() {
    this.showChild = false;
  }
  changeOutCount(scope: any) {
    console.log(scope.row);
    if (scope.row.outCount > scope.row.material_all_count) {
      console.log('数量超了');
    }
  }
  confirm() {
    let temp = this.tableData[0];
    if (!temp.outCount) {
      this.$message.error('入库数量未填写');
      return;
    }
    this.showCheck = true;
    this.checkMessage = temp.outCount;
  }
  secondConfirm(): void {
    this.showCheck = false;
    let temp = this.tableData[0];
    console.log(temp);
    let goodsData: any = {};
    goodsData = {
      goods_id: temp.goods_id,
      number: temp.outCount === '0' ? temp.outCount : temp.outCount,
      remarks: temp.tableRemark ? temp.tableRemark : ''
    };
    // return;
    let data: any = {
      goodsInfo: JSON.stringify(goodsData),
      orderId: this.id,
      doName: this.doname,
      date: this.date,
      remarks: this.remark,
      state: '生产入库'
    };
    this.createRes.getFunction(data).then((res:any) => {
      if (res.data.code === 1) {
        this.$to('productList');
      }
    });
  }
}
</script>
<style lang="less">
.toStroke {
  height: 100%;
  padding: 15px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow-y: auto;
  position: relative;
  .top-card {
    // padding: 10px;
    box-sizing: border-box;
    margin-bottom: 15px;
  }
  .el-card {
    overflow-y: auto;
  }
  .content {
    font-size: 16px;
    background-color: #fff;
    border-radius: 4px;
    .content-title {
      height: 40px;
      margin-top: 20px;
      line-height: 2;
      text-align: left;
    }
    .short-input {
      width: 100%;
      width: 240px;
      margin-right: 10px;
    }
    .el-upload-list__item {
      width: 350px;
    }
    .el-textarea {
      margin-bottom: 30px;
    }
  }
  .card-title {
    text-align: left;
    font-weight: 600;
  }
  .first {
    margin-bottom: 15px;
    text-align: left;
    // display: flex;
    // flex-direction: row;
    .first-title {
      display: flex;
      margin-bottom: 20px;
    }
    .left {
      margin-right: 40px;
      // float: left;
      // height: 100%;
    }
    .big-wrod {
      font-size: 24px;
      color: red;
    }
    .right {
      font-size: 14px;
      div {
        min-width: 140px;
        margin-right: 10px;
      }
      .big {
        font-weight: 600;
      }
    }
    .right-top {
      display: flex;
      margin-bottom: 10px;
    }
  }
  .red {
    color: red;
  }
  .confirms {
    margin-top: 15px;
  }
  .back {
    position: absolute;
    right: 15px;
    top: 15px;
  }
}
</style>
